package com.weizhizs.assistant.code;

import com.weizhizs.assistant.code.dao.GeneratorDao;
import com.weizhizs.assistant.code.vo.EnumVO;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@EqualsAndHashCode(callSuper = true)
@Data
public class EnumGeneratorRunner extends GeneratorRunner{

    @Override
    public void generate() {
        Map<String, EnumCodeGenerator> generators = EnumGeneratorRegister.codeGenerators();

        Map<String, List<EnumVO>> enumList = GeneratorDao.getInstance().getEnumList();
        if (enumList.isEmpty()) {
            System.out.println("enumList is null." );
            return;
        }
        List<String> enumNames = new ArrayList<>(enumList.keySet());

        for (String enumName : enumNames) {
            EnumVO newEnum = new EnumVO();
            newEnum.setParamType(enumName);
            newEnum.setTypeName(enumList.get(enumName).get(0).getTypeName());
            newEnum.setAllParam(enumList.get(enumName));

            for (EnumCodeGenerator generator : generators.values()) {
                generator.run(newEnum);
            }
        }
    }

}
